﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using gfLibrary;
using System.Drawing;
using System.Data;
using IYAKASAPortal.Services;
using System.Xml.Linq;
using System.IO;
using System.Xml;
using DBUtility;

namespace IYAKASAPortal.Login
{
    public partial class LoginZJGC : System.Web.UI.Page
    {
        private static List<ListItem> lstItemsGC { get; set; }
        private UserInfo userInfo { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
            {
                string userName = Session["UserName"].ToString();
                userInfo = IYAKASAPortal.Services.UserAuthority.GetUserAuthority(userName);
            }
            else
            {
                gfJs.RunFunction(this.Page, "parent.window.location = '../logout.aspx';");
            }
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            lstItemsGC = new List<ListItem>();
            CONST_DEFINE_BLL bll = new CONST_DEFINE_BLL();
            var def = bll.GetModelList("CON_CHNAME='JYLB' and CON_VTYPE='0' order by CON_ORDER asc");

            ListItem item;
            foreach (var v in def)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpJYLBGC.Items.Add(item);
            }

            var hpzl = bll.GetModelList("CON_CHNAME='HPZL' and CON_CODE=15 order by CON_ORDER asc");
            foreach (var v in hpzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpHPZLGC.Items.Add(item);
            }

            var syxz = bll.GetModelList("CON_CHNAME='SYXZ' order by CON_ORDER asc");
            foreach (var v in syxz)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpSYXZGC.Items.Add(item);
            }

            var gcclzl = bll.GetModelList("CON_CHNAME='CLZL' and SUBSTRING(CON_CODE,1,1)='B' order by CON_ORDER asc");
            foreach (var v in gcclzl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpCLZLGC.Items.Add(item);
            }

            var csys = bll.GetModelList("CON_CHNAME='CSYS' order by CON_ORDER asc");
            foreach (var v in csys)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpCSYSGC.Items.Add(item);
            }

            var lwcxwzjl = bll.GetModelList("CON_CHNAME='LWCXWZJL' order by CON_ORDER asc");
            foreach (var v in lwcxwzjl)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpLWCXWZJLGC.Items.Add(item);
            }

            var bzzxs = bll.GetModelList("CON_CHNAME='BZZXS' order by CON_CODE asc");
            foreach (var v in bzzxs)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpBZZXSGC.Items.Add(item);
            }

            var hccsxs = bll.GetModelList("CON_CHNAME='HCCSXS' order by CON_CODE asc");
            foreach (var v in hccsxs)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CON;
                drpHCCSXSGC.Items.Add(item);
            }

            var clcclx = bll.GetModelList("CON_CHNAME='CLCCLX' order by CON_ORDER asc");
            foreach (var v in clcclx)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpCLCCLXGC.Items.Add(item);
            }

            var zjcllx = bll.GetModelList("CON_CHNAME='ZJCLLX' order by CON_ORDER asc");
            foreach (var v in zjcllx)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                drpZJCLLXGC.Items.Add(item);
            }

            var jyxm = bll.GetModelList("CON_CHNAME='JYXM' and CON_JCTYPE like '%04,%' order by CON_ORDER asc");
            foreach (var v in jyxm)
            {
                item = new ListItem();
                item.Text = v.CON_CON;
                item.Value = v.CON_CODE;
                lstItemsGC.Add(item);
            }

            for (int i = 2; i < 7; i++)
            {
                item = new ListItem();
                item.Text = i.ToString() + "";
                item.Value = i.ToString();
                drpZZSGC.Items.Add(item);
            }

            //绑定号码开头
            CONST_DEFINE_WEB_CATEGORY_BLL category_bll = new CONST_DEFINE_WEB_CATEGORY_BLL();
            var hphmStart = category_bll.GetModel(8);
            txtHPHMStartGC.Text = hphmStart.CategoryName;

            LoginHelper.BindZCZWZ(Convert.ToInt32(drpZZSGC.SelectedValue), chkZCZWZGC);

            drpZZSGC_SelectedIndexChanged(null, null);

            LoginHelper.BindJCXMGC_ZJ(Convert.ToInt32(drpZZSGC.SelectedValue), chkJYXMGC, lstItemsGC);
        }

        protected void chkAllGC_CheckedChanged(object sender, EventArgs e)
        {
            LoginHelper.CheckAll(chkJYXMGC, chkAllGC.Checked);
        }

        protected void btnSaveGC_Click(object sender, EventArgs e)
        {
            string strJYLBGC = drpJYLBGC.SelectedValue + ",";
            string strZJLSHGC = txtZJLSHGC.Text.Trim();
            string strHPHMGC_C = txtHPHMGC.Text.Trim().ToUpper();
            string strHPHMGC_H = txtHPHMStartGC.Text.Trim().ToUpper();
            string strHPHMGC = strHPHMGC_H + strHPHMGC_C;
            if (!strHPHMGC.Contains("挂"))
            {
                strHPHMGC += "挂";
            }

            string strHPZLGC = drpHPZLGC.SelectedValue;
            string strVINGC = txtVINGC.Text.Trim().ToUpper();

            string strVEHICLEIDGC = strHPZLGC + strHPHMGC;
            string strCLZLGC = drpCLZLGC.SelectedValue;
            string strSYRGC = txtSYRGC.Text.Trim();
            string strAddressGC = txtAddressGC.Text.Trim();
            string strSYXZGC = drpSYXZGC.SelectedValue;
            string strPPGC = txtPPGC.Text.Trim();
            string strXHGC = txtXHGC.Text.Trim();
            string strCCRQGC = txtCCRQGC.Text.Trim();
            string strCCDJRQGC = txtCSDJRQGC.Text.Trim();
            string strZZLGC = txtZZLGC.Text.Trim();
            string strZBZLGC = txtZBZLGC.Text.Trim();
            string strHDZZLGC = txtHDZZLGC.Text.Trim();
            string strCSCGC = txtCSCGC.Text.Trim();
            string strCSKGC = txtCSKGC.Text.Trim();
            string strCSGGC = txtCSGGC.Text.Trim();
            string strZZSGC = drpZZSGC.SelectedValue;
            string strZCZWZGC = "";
            string strZJCLLXGC = drpZJCLLXGC.SelectedValue;
            string strTestStatus = rbtnTestGC.SelectedValue;
            string strWCXWZJLGC = drpLWCXWZJLGC.SelectedValue;
            string strHCCSXSGC = drpHCCSXSGC.SelectedValue;
            string strYYZHGC = txtYYZHGC.Text.Trim();
            string strCLCCLXGC = drpCLCCLXGC.SelectedValue;
            string strBZZXSGC = drpBZZXSGC.SelectedValue;
            string strJYXMGC = "";

            if (string.IsNullOrEmpty(strHPHMGC_H))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车号牌号码开头不能为空！");
                txtHPHMStartGC.Focus();
                txtHPHMStartGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtHPHMStartGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strHPHMGC_C))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车号牌号码不能为空！");
                txtHPHMGC.Focus();
                txtHPHMGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtHPHMGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCCRQGC) == false)
            {
                if (gfValidate.Is_DateTime(strCCRQGC) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车出厂年月不是有效的日期格式！");
                    txtCCRQGC.Focus();
                    txtCCRQGC.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtCCRQGC.BackColor = Color.White;
                }
            }

            if (string.IsNullOrEmpty(strCCDJRQGC) == false)
            {
                if (gfValidate.Is_DateTime(strCCRQGC) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车初始登记日期不是有效的日期格式！");
                    txtCSDJRQGC.Focus();
                    txtCSDJRQGC.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtCSDJRQGC.BackColor = Color.White;
                }
            }

            if (string.IsNullOrEmpty(strZZLGC) == false && !gfValidate.Is_Integer(strZZLGC))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车总质量不是整数！");
                txtZZLGC.Focus();
                txtZZLGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtZZLGC.BackColor = Color.White;
            }

            if (!string.IsNullOrEmpty(strZBZLGC) && !gfValidate.Is_Integer(strZBZLGC))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车整备质量不是整数！");
                txtZBZLGC.Focus();
                txtZBZLGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtZBZLGC.BackColor = Color.White;
            }

            if (!string.IsNullOrEmpty(strHDZZLGC))
            {
                if (gfLibrary.gfValidate.Is_Integer(strHDZZLGC) == false)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车核定载质量不是整数！");
                    txtHDZZLGC.Focus();
                    txtHDZZLGC.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtHDZZLGC.BackColor = Color.White;
                }
            }

            if (string.IsNullOrEmpty(strCSCGC) == false && gfValidate.Is_Integer(strCSCGC) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车车身长不是整数！");
                txtCSCGC.Focus();
                txtCSCGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtCSCGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCSKGC) == false && gfValidate.Is_Integer(strCSKGC) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车车身宽不是整数！");
                txtCSKGC.Focus();
                txtCSKGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtCSKGC.BackColor = Color.White;
            }

            if (string.IsNullOrEmpty(strCSGGC) == false && gfValidate.Is_Integer(strCSGGC) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "挂车车身高不是整数！");
                txtCSGGC.Focus();
                txtCSGGC.BackColor = Color.Yellow;
                return;
            }
            else
            {
                txtCSGGC.BackColor = Color.White;
            }

            for (int i = 0; i < chkZCZWZGC.Items.Count; i++)
            {
                if (chkZCZWZGC.Items[i].Selected)
                {
                    strZCZWZGC += chkZCZWZGC.Items[i].Value + ",";
                }
            }

         
            bool bTogether = chkTogether.Checked;
            string strGLHPHM = "";
            if (bTogether)
            {
                strGLHPHM = txtGLHPHM.Text.Trim();
                if (string.IsNullOrEmpty(strGLHPHM))
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "关联号牌号码不能为空！");
                    txtGLHPHM.Focus();
                    txtGLHPHM.BackColor = Color.Yellow;
                    return;
                }
                else
                {
                    txtGLHPHM.BackColor = Color.White;
                }
            }

            for (int i = 0; i < chkJYXMGC.Items.Count; i++)
            {
                if (chkJYXMGC.Items[i].Selected)
                {
                    strJYXMGC += chkJYXMGC.Items[i].Value + ",";
                }
            }

            for (int i = 0; i < chkZCZWZGC.Items.Count; i++)
            {
                if (chkZCZWZGC.Items[i].Selected)
                {
                    strZCZWZGC += chkZCZWZGC.Items[i].Value + ",";
                }
            }

            LOGIN_VEHICLE_INFO info_GC = new LOGIN_VEHICLE_INFO();
            info_GC.VEHICLEID = strHPZLGC + strHPHMGC;
            info_GC.HPHM = strHPHMGC;
            info_GC.HPZL = drpHPZLGC.SelectedItem.Text;
            info_GC.HPZLDH = strHPZLGC;
            info_GC.VIN = strVINGC;
            info_GC.JYLB = drpJYLBGC.SelectedItem.Text;
            info_GC.JYLBDH = strJYLBGC;
            info_GC.PP = strPPGC;
            info_GC.XH = strXHGC;
            info_GC.PPXH = strPPGC + strXHGC;
            info_GC.ZCZWZ = strZCZWZGC;
            info_GC.CCDJRQ = strCCDJRQGC;
            info_GC.CCRQ = strCCRQGC;
            info_GC.CSYS = drpCSYSGC.SelectedItem.Text;
            info_GC.CSYSDH = drpCSYSGC.SelectedValue;
            info_GC.ZBZL = strZBZLGC;
            info_GC.ZZL = strZZLGC;
            info_GC.SYR = strSYRGC;
            info_GC.LXDZ = strAddressGC;
            info_GC.SYXZ = drpSYXZGC.SelectedItem.Text;
            info_GC.SYXZDH = drpSYXZGC.SelectedItem.Value;
            info_GC.HDZH = strHDZZLGC;
            info_GC.JYXM_LW = strJYXMGC;
            info_GC.JYXM = strJYXMGC;
            info_GC.CSC = strCSCGC;
            info_GC.CSK = strCSKGC;
            info_GC.CSG = strCSGGC;
            info_GC.DLY = userInfo.UserName;
            info_GC.LWCXWZJLDH = drpLWCXWZJLGC.SelectedItem.Value;
            info_GC.LWCXWZJL = drpLWCXWZJLGC.SelectedItem.Text;
            info_GC.ZZS = drpZZSGC.SelectedItem.Value;
            if (bTogether)
            {
                info_GC.GLCHPHM = txtGLHPHM.Text.Trim();
            }

            //综检
            info_GC.YYZH = strYYZHGC;
            info_GC.BZZXS = drpBZZXSGC.SelectedItem.Text;
            info_GC.BZZXSDH = drpBZZXSGC.SelectedItem.Value;
            info_GC.HCCSXS = drpHCCSXSGC.SelectedItem.Value;
            info_GC.CLCCLX = drpCLCCLXGC.SelectedItem.Text;
            info_GC.CLCCLXDH = drpCLCCLXGC.SelectedItem.Value;
            info_GC.ZJCLLX = drpZJCLLXGC.SelectedItem.Text;
            info_GC.ZJCLLXDH = drpZJCLLXGC.SelectedItem.Value;

            LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
            var vRet_Login_GC = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLGC);

            DbFactory factory = new DbFactory();

            if (vRet_Login_GC != null)
            {
                factory.Add(bll.UpdateSQL(info_GC, vRet_Login_GC.ID));
            }
            else
            {
                factory.Add(bll.InsertSQL(info_GC));
            }

            if (string.IsNullOrEmpty(userInfo.UserName))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前没有授权,请退出系统重新登录！");
                return;
            }

            bool bOnGoing = LoginHelper.GetVehicleStatus(strVEHICLEIDGC);
            if (bOnGoing)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车辆【" + strVEHICLEIDGC + "】正在检测，不能保存当前信息！");
                return;
            }

            bool bRet = factory.Execute();
            if (bRet)
            {
                hidGCID.Value = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLGC).ID.ToString();
                LoginHelper.SavePPXHAndFDJXH(info_GC);
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车牌号码【" + strHPHMGC + "】保存成功！");
                btnSendGC.Enabled = true;
                btnSendGC.CssClass = "btnSendEnabled";
            }
            else
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "车牌号码【" + strHPHMGC + "】保存失败！");
                return;
            }
        }

        private void ResetAllGC()
        {
            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpJYLBGC.ID, ""));
            lstControls.Add(drpJYLBGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZJLSHGC.ID, ""));
            lstControls.Add(txtZJLSHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMGC.ID, ""));
            lstControls.Add(txtHPHMGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZLGC.ID, ""));
            lstControls.Add(drpHPZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID, "2,"));
            lstControls.Add(chkZCZWZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtVINGC.ID, ""));
            lstControls.Add(txtVINGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID, ""));
            lstControls.Add(drpCLZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYRGC.ID, ""));
            lstControls.Add(txtSYRGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddressGC.ID, ""));
            lstControls.Add(txtAddressGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZGC.ID, ""));
            lstControls.Add(drpSYXZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtPPGC.ID, ""));
            lstControls.Add(txtPPGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCSYSGC.ID, ""));
            lstControls.Add(drpCSYSGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtXHGC.ID, ""));
            lstControls.Add(txtXHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQGC.ID, ""));
            lstControls.Add(txtCCRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSDJRQGC.ID, ""));
            lstControls.Add(txtCSDJRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID, ""));
            lstControls.Add(txtZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID, ""));
            lstControls.Add(txtZBZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID, ""));
            lstControls.Add(txtHDZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID, ""));
            lstControls.Add(txtCSCGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID, ""));
            lstControls.Add(txtCSKGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID, ""));
            lstControls.Add(txtCSGGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpZJCLLXGC.ID, ""));
            lstControls.Add(drpZJCLLXGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpLWCXWZJLGC.ID, ""));
            lstControls.Add(drpLWCXWZJLGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHCCSXSGC.ID, ""));
            lstControls.Add(drpHCCSXSGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtYYZHGC.ID, ""));
            lstControls.Add(txtYYZHGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLCCLXGC.ID, ""));
            lstControls.Add(drpCLCCLXGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpBZZXSGC.ID, ""));
            lstControls.Add(drpBZZXSGC);

            lstCtl.Add(new LoginHelper.ControlNames(rbtnTestGC.ID, ""));
            lstControls.Add(rbtnTestGC);

            lstCtl.Add(new LoginHelper.ControlNames(chkJYXMGC.ID, ""));
            lstControls.Add(chkJYXMGC);

            foreach (var v in lstItemsGC)
            {
                v.Selected = false;
            }

            hidGCID.Value = "";

            LoginHelper.ResetAllControls(lstCtl, lstControls);
            drpZZSGC_SelectedIndexChanged(null, null);

            chkTogether.Checked = false;
            txtGLHPHM.Text = "";
            chkTogether_CheckedChanged(null, null);

            btnSaveGC.Enabled = true;
            btnSaveGC.CssClass = "btnSaveEnabled";
        }

        protected void btnSearchGC_Click(object sender, EventArgs e)
        {
            string strHPHMGCStart = txtHPHMStartGC.Text.Trim().ToUpper();
            string strHPHM = strHPHMGCStart + txtHPHMGC.Text.Trim().ToUpper();
            string strVIN = txtVINGC.Text.Trim();
            string strHPZL = drpHPZLGC.SelectedItem.Value;

            if (string.IsNullOrEmpty(strHPHM) && string.IsNullOrEmpty(strVIN))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请输入号牌号码或者VIN进行查询！");
                return;
            }

            if (!strHPHM.Contains("挂"))
            {
                strHPHM = strHPHM + "挂";
            }
            if (chkSFLWGC.Checked)
            {
                string strJYJGBH = "xxxx";

                string xtlb = "";//系统类别
                string jkxlh = "";//接口序列号
                string jkid = "";//接口标志

                var doc = new XDocument(
                    new XElement("root",
                        new XElement("QueryCondition",
                            new XElement("hphm", strHPHM),
                            new XElement("hpzl", strHPZL),
                            new XElement("clsbdh", strVIN),
                            new XElement("jyjgbh", strJYJGBH)
                            )
                        )
                    );
                string QueryXmlDoc = doc.ToString();

                localhost.myWebService call = new localhost.myWebService();
                string result = call.queryObjectOutz(xtlb, jkxlh, jkid, QueryXmlDoc);

                StringReader reader = new StringReader(result);
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode root = xmlDoc.SelectSingleNode("//vehispara");
                if (root != null)
                {
                    LOGIN_VEHICLE_INFO info = new LOGIN_VEHICLE_INFO();
                    info.JYLBDH = root.SelectSingleNode("jylb").InnerText;
                    info.ZYWLBDH = root.SelectSingleNode("ywlx").InnerText;
                    info.HPHM = root.SelectSingleNode("hphm").InnerText;
                    info.HPZLDH = root.SelectSingleNode("hpzl").InnerText;
                    info.VIN = root.SelectSingleNode("clsbdh").InnerText;


                    info.SYR = root.SelectSingleNode("syr").InnerText;
                    info.LXDZ = root.SelectSingleNode("zsxzqh").InnerText;
                    info.SYXZDH = root.SelectSingleNode("syxz").InnerText;
                    info.PP = root.SelectSingleNode("clpp1").InnerText;
                    info.XH = root.SelectSingleNode("clxh").InnerText;
                    info.CCRQ = root.SelectSingleNode("ccrq").InnerText;
                    info.CCDJRQ = root.SelectSingleNode("ccdjrq").InnerText;
                    info.FDJH = root.SelectSingleNode("fdjh").InnerText;
                    info.CSYS = root.SelectSingleNode("csys").InnerText;
                    info.CYS = root.SelectSingleNode("hdzk").InnerText;
                    info.ZZL = root.SelectSingleNode("zzl").InnerText;
                    info.ZBZL = root.SelectSingleNode("zbzl").InnerText;
                    info.HDZH = root.SelectSingleNode("hdzzl").InnerText;
                    info.CSC = root.SelectSingleNode("cwkc").InnerText;
                    info.CSG = root.SelectSingleNode("cwkg").InnerText;
                    info.CSK = root.SelectSingleNode("cwkk").InnerText;
                    info.ZXZLXDH = root.SelectSingleNode("zxxs").InnerText;
                    info.ZXZXJXSDH = root.SelectSingleNode("zxzxjxs").InnerText;
                    info.QZDZDH = root.SelectSingleNode("qzdz").InnerText;
                    info.YGGSNFKTDH = root.SelectSingleNode("ygddtz").InnerText;
                    info.ZCZWZ = root.SelectSingleNode("zczw").InnerText;
                    info.QDXSDH = root.SelectSingleNode("qdxs").InnerText;
                    info.JZZZWZ = root.SelectSingleNode("jzzzwz").InnerText;
                    info.RLLBDH = root.SelectSingleNode("rlzl").InnerText;
                    info.ZGSJCS = root.SelectSingleNode("zgsjcs").InnerText;
                    info.LWCXWZJLDH = root.SelectSingleNode("lwcxwzjldh").InnerText;

                    info.EDGL = root.SelectSingleNode("edgl").InnerText;
                    info.EDNJ = root.SelectSingleNode("ednj").InnerText;
                    info.EDNJZS = root.SelectSingleNode("ednjzs").InnerText;
                    info.LTGGLXDH = root.SelectSingleNode("ltgglx").InnerText;
                    info.KCLXDJ = root.SelectSingleNode("kclxdj").InnerText;
                    info.YZLJ = root.SelectSingleNode("qlj").InnerText;
                    info.QDZKZZL = root.SelectSingleNode("qdzkzzl").InnerText;
                    info.HDZH = root.SelectSingleNode("hdzh").InnerText;
                    info.LJXSLC = root.SelectSingleNode("ljxslc").InnerText;
                    info.YYZH = root.SelectSingleNode("yyzh").InnerText;
                    info.XZQY = root.SelectSingleNode("xzqy").InnerText;
                    info.BZZXSDH = root.SelectSingleNode("bzzxs").InnerText;
                    info.HCCSXS = root.SelectSingleNode("hccsxs").InnerText;
                    info.CLCCLXDH = root.SelectSingleNode("clcclx").InnerText;
                    info.ZZS = root.SelectSingleNode("zzs").InnerText;
                    info.DCZS = root.SelectSingleNode("dczs").InnerText;
                    info.GCZS = root.SelectSingleNode("gczs").InnerText;
                    info.ZJCLLXDH = root.SelectSingleNode("zjcllx").InnerText;
                    info.SFSWPC = root.SelectSingleNode("sfswpc").InnerText;
                    info.YCY = root.SelectSingleNode("ycy").InnerText;


                }
                else
                {
                    Response.Write("the node is not existed");
                }
            }
            else
            {
                LOGIN_VEHICLE_INFO_BLL bll = new LOGIN_VEHICLE_INFO_BLL();
                string strSql = "";
                if (!string.IsNullOrEmpty(strHPHM))
                {
                    strSql = "VEHICLEID='" + strHPZL + strHPHM + "' and HPZLDH='" + strHPZL + "'";
                }
                else if (!string.IsNullOrEmpty(strVIN))
                {
                    strSql = "VIN='" + strVIN + "' and HPZLDH='" + strHPZL + "'";
                }

                LOGIN_VEHICLE_INFO[] infos = bll.GetModelList(strSql);

                if (infos.Length == 1)
                {
                    BindQCLC(infos[0].HPHM, infos[0].HPZLDH);
                    hidGCID.Value = infos[0].ID.ToString();
                }
                else if (infos.Length > 1)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果大于1条，显示为第一条！");
                    BindQCLC(infos[0].HPHM, infos[0].HPZLDH);
                    hidGCID.Value = infos[0].ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "查询结果为空！");
                    ResetAllGC();
                }
            }
        }

        private void BindQCLC(string strHPHMGC, string strHPZLDHGC)
        {
            var vInfo = LoginHelper.GetLoginInfo(strHPHMGC, strHPZLDHGC);

            //总轴数
            if (string.IsNullOrEmpty(vInfo.ZZS) == false)
            {
                drpZZSGC.SelectedValue = vInfo.ZZS;
                drpZZSGC_SelectedIndexChanged(null, null);
            }

            List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
            List<Control> lstControls = new List<Control>();

            lstCtl.Add(new LoginHelper.ControlNames(drpJYLBGC.ID.ToString(), "JYLBDH"));
            lstControls.Add(drpJYLBGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZJLSHGC.ID.ToString(), "ZJLSH"));
            lstControls.Add(txtZJLSHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHPHMGC.ID.ToString(), "HPHM"));
            lstControls.Add(txtHPHMGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHPZLGC.ID.ToString(), "HPZLDH"));
            lstControls.Add(drpHPZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtVINGC.ID.ToString(), "VIN"));
            lstControls.Add(txtVINGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID.ToString(), "CLZLDH"));
            lstControls.Add(drpCLZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtSYRGC.ID.ToString(), "SYR"));
            lstControls.Add(txtSYRGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtAddressGC.ID.ToString(), "LXDZ"));
            lstControls.Add(txtAddressGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpSYXZGC.ID.ToString(), "SYXZDH"));
            lstControls.Add(drpSYXZGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtPPGC.ID.ToString(), "PP"));
            lstControls.Add(txtPPGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtXHGC.ID.ToString(), "XH"));
            lstControls.Add(txtXHGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCCRQGC.ID.ToString(), "CCRQ"));
            lstControls.Add(txtCCRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSDJRQGC.ID.ToString(), "CCDJRQ"));
            lstControls.Add(txtCSDJRQGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID.ToString(), "ZZL"));
            lstControls.Add(txtZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCSYSGC.ID, "CSYSDH"));
            lstControls.Add(drpCSYSGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID.ToString(), "ZBZL"));
            lstControls.Add(txtZBZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID.ToString(), "HDZH"));
            lstControls.Add(txtHDZZLGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID.ToString(), "CSC"));
            lstControls.Add(txtCSCGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID.ToString(), "CSK"));
            lstControls.Add(txtCSKGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID.ToString(), "CSG"));
            lstControls.Add(txtCSGGC);

            lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID.ToString(), "ZCZWZ"));
            lstControls.Add(chkZCZWZGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpLWCXWZJLGC.ID.ToString(), "LWCXWZJLDH"));
            lstControls.Add(drpLWCXWZJLGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpZJCLLXGC.ID.ToString(), "ZJCLLXDH"));
            lstControls.Add(drpZJCLLXGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpHCCSXSGC.ID.ToString(), "HCCSXS"));
            lstControls.Add(drpHCCSXSGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtYYZHGC.ID.ToString(), "YYZH"));
            lstControls.Add(txtYYZHGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpCLCCLXGC.ID.ToString(), "CLCCLX"));
            lstControls.Add(drpCLCCLXGC);

            lstCtl.Add(new LoginHelper.ControlNames(drpBZZXSGC.ID.ToString(), "BZZXSDH"));
            lstControls.Add(drpBZZXSGC);

            lstCtl.Add(new LoginHelper.ControlNames(txtXZQYGC.ID.ToString(), "XZQY"));
            lstControls.Add(txtXZQYGC);

            LoginHelper.LoadData(vInfo, lstCtl, lstControls);

            string strJYXM = "";
            LoginHelper.ConfirmJCXS(vInfo, "Z", rbtnTestGC, lblJCCSGC, out strJYXM);

            if (!string.IsNullOrEmpty(vInfo.GLCHPHM))
            {
                chkTogether.Checked = true;
                txtGLHPHM.Text = vInfo.GLCHPHM;
            }
            else
            {
                chkTogether.Checked = false;
                txtGLHPHM.Text = "";
            }

            if (rbtnTestGC.SelectedValue == "0")
            {
                strJYXM = vInfo.JYXM;
            }

            LoginHelper.BindJYXM(strJYXM, chkJYXMGC, lstItemsGC);
        }


        protected void btnResetGC_Click(object sender, EventArgs e)
        {
            ResetAllGC();
        }

        protected void drpZZSGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            int iZZS = Convert.ToInt32(drpZZSGC.SelectedValue);
            LoginHelper.BindJCXMGC_ZJ(iZZS, chkJYXMGC, lstItemsGC);
            LoginHelper.BindZCZWZ(iZZS, chkZCZWZGC);
        }

        protected void chkZCZWZGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool b = false;
            for (int i = 0; i < chkZCZWZGC.Items.Count; i++)
            {
                if (chkZCZWZGC.Items[i].Selected)
                {
                    b = true;
                }
            }

            if (b == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "必须选择一个驻车轴！");
                chkZCZWZGC.Items[0].Selected = true;
                return;
            }
        }

        protected void chkJYXMGC_SelectedIndexChanged(object sender, EventArgs e)
        {
            bool bFirstTest = rbtnTestGC.SelectedValue == "0" ? true : false;
            LoginHelper.JYXMChanged(chkJYXMGC, lstItemsGC, bFirstTest);
        }

        protected void btnSendGC_Click(object sender, EventArgs e)
        {
            bool bIsFirstTest_GC = rbtnTestGC.SelectedValue == "0" ? true : false;//是否为初检
            bool bIsUpdate_GC;

            //bool bHasCharge_GC = LoginHelper.HasCharge(hidGCID.Value, "Z", bIsFirstTest_GC);
            //if (!bHasCharge_GC)
            //{
            //    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "当前【挂车】没有收费，请收费后在发送！");
            //    return;
            //}

            var dicCheckItems = LoginHelper.CheckAllInputItems("", hidGCID.Value, "Z");
            if (dicCheckItems["ZG"].Count > 0)
            {
                foreach (var v in dicCheckItems["ZG"])
                {
                    TextBox txt = (TextBox)this.FindControl(v);
                    txt.BackColor = Color.Yellow;
                }
                return;
            }

            LOGIN_VEHICLE_INFO_BLL info_bll = new LOGIN_VEHICLE_INFO_BLL();
            var infoGC = info_bll.GetModel(Convert.ToInt32(hidGCID.Value));
            if (string.IsNullOrEmpty(infoGC.JYXM))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择检验挂车项目保存后，在进行发送！");
                return;
            }

            VEHICLE_DISPATCH model_GC = LoginHelper.GetDispathchByLoginID(hidGCID.Value, "Z", bIsFirstTest_GC, out bIsUpdate_GC);

            VEHICLE_DISPATCH_BLL disBll = new VEHICLE_DISPATCH_BLL();

            DbFactory factory = new DbFactory();

            if (bIsUpdate_GC)
            {
                factory.Add(disBll.UpdateSQL(model_GC, model_GC.JCLSH));
            }
            else
            {
                factory.Add(disBll.InsertSQL(model_GC));
            }

            if (factory.Execute())
            {
                gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送成功！");
                ResetAllGC();
                btnSendGC.CssClass = "btnSendDisabled";
                btnSendGC.Enabled = false;
                LoginedList1.BindList("", "");
                return;
            }
            else
            {
                gfAjaxJs.SetAlertMsg(UpdatePanel1, "发送失败！");
                btnSendGC.CssClass = "btnSendEnabled";
                btnSendGC.Enabled = true;
                return;
            }
        }

        protected void btnSearchGCPPXH_Click(object sender, EventArgs e)
        {
            string strPPGC = txtPPGC.Text.Trim();
            string strXHGC = txtXHGC.Text.Trim();
            TYPE_CX_CONTENT_BLL bll = new TYPE_CX_CONTENT_BLL();
            TYPE_CX_CONTENT[] m_TYPE_CX_CONTENT = bll.GetModelList("PP='" + strPPGC + "' and XH='" + strXHGC + "' order by ID desc");

            if (m_TYPE_CX_CONTENT.Length > 0)
            {
                TYPE_CX_CONTENT vContent = m_TYPE_CX_CONTENT[0];

                if (!string.IsNullOrEmpty(vContent.ZZS))
                {
                    drpZZSGC.SelectedValue = vContent.ZZS;
                    drpZZSGC_SelectedIndexChanged(null, null);
                }

                List<LoginHelper.ControlNames> lstCtl = new List<LoginHelper.ControlNames>();
                List<Control> lstControls = new List<Control>();

                lstCtl.Add(new LoginHelper.ControlNames(chkZCZWZGC.ID.ToString(), "ZCZWZ"));
                lstControls.Add(chkZCZWZGC);

                lstCtl.Add(new LoginHelper.ControlNames(drpCLZLGC.ID.ToString(), "CLZL"));
                lstControls.Add(drpCLZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtZZLGC.ID.ToString(), "ZZL"));
                lstControls.Add(txtZZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtZBZLGC.ID.ToString(), "ZBZL"));
                lstControls.Add(txtZBZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtHDZZLGC.ID.ToString(), "HDZH"));
                lstControls.Add(txtHDZZLGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSCGC.ID.ToString(), "CSC"));
                lstControls.Add(txtCSCGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSKGC.ID.ToString(), "CSK"));
                lstControls.Add(txtCSKGC);

                lstCtl.Add(new LoginHelper.ControlNames(txtCSGGC.ID.ToString(), "CSG"));
                lstControls.Add(txtCSGGC);

                LoginHelper.GetPPXH(vContent, lstCtl, lstControls);
            }
        }

        protected void chkTogether_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTogether.Checked)
            {
                txtGLHPHM.ReadOnly = false;
                txtGLHPHM.CssClass = "csstextbox";
            }
            else
            {
                txtGLHPHM.ReadOnly = true;
                txtGLHPHM.CssClass = "csstextboxreadonly";
            }
        }

        protected void lbtnLoginedShow_Click(object sender, EventArgs e)
        {
            if (divLoginList.Visible == false)
            {
                lbtnLoginedShow.Text = "收 起︽";
                divLoginList.Visible = true;
            }
            else
            {
                lbtnLoginedShow.Text = "展 开︾";
                divLoginList.Visible = false;
            }
        }
    }
}